# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libssh
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.7.5
pkgrel=1
pkgdesc="Library for accessing ssh client services through C libraries (mingw-w64)"
arch=('any')
url="https://www.libssh.org/"
license=("LGPL")
install=libssh-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
validpgpkeys=('8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D') # Andreas Schneider <asn@cryptomilk.org>
source=(https://red.libssh.org/attachments/download/218/${_realname}-${pkgver}.tar.xz
        https://red.libssh.org/attachments/download/217/${_realname}-${pkgver}.tar.asc
        mingw-as-unix.patch
        mingw-DATADIR-conflict.patch
        fix-threads-libraryname-in-config.patch)
sha256sums=('54e86dd5dc20e5367e58f3caab337ce37675f863f80df85b6b1614966a337095'
            'SKIP'
            '3e95048aa0acf0a639120cb732dcce14ea1e51a7ed59b18a25e05001ebabd241'
            '444a66b1926f49c54df844c22263496c2d86e124c8bcdbd194c4581d06140c1b'
            'a69b444d4a9b1861991661d5f3ca8d2ab705fac1f5766a79730328b0bdd86691')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/mingw-as-unix.patch
  patch -p1 -i ${srcdir}/mingw-DATADIR-conflict.patch
  patch -p1 -i ${srcdir}/fix-threads-libraryname-in-config.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_STATIC_LIB=ON \
    ../${_realname}-${pkgver}

  make all
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
